package com.qt.myio;

import java.io.*;

/**
 * @Author zsf
 * @Date 2023/9/24 23:57
 * @Version 1.0
 */
public class ByteStreamDemo04 {

    public static void main(String[] args) throws IOException {

        /**
         * 复制文件夹
         */

        File src = new File("D:\\java测试目录\\aaasrc");
        File desk = new File("D:\\java测试目录\\aaadesk");
        copyDir( src, desk);




    }

    /**
     * 文件夹 复制
     * @param src
     * @param desk
     * @throws IOException
     */
    public static void copyDir(File src,File desk) throws IOException {
        desk.mkdirs();
        File[] files = src.listFiles();
        for (File file : files) {
            if(file.isFile()){
                FileInputStream fis = new FileInputStream(file);
                FileOutputStream fos = new FileOutputStream(new File(desk,file.getName()));
                int len;
                byte[] bytes = new byte[1024];
                while ((len = fis.read(bytes)) != -1){
                    fos.write(bytes,0,len);
                }
                fos.close();
                fis.close();

            }else {
                //递归
                copyDir(file,new File(desk,file.getName()));

            }
        }


    }



}
